<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace App\Core;  
Class Factory{
    private static $obj_arr = array();
    public function __construct(){
        
    }
    /*
       * 2015-09-20 create new class 
       *  @param string classname   
       *  @param array  $param_arr
       *  return class obj
       */
    
    public static function createObj($classname, $param_arr = array()){
        if(array_key_exists($classname,self::$obj_arr)){
            return self::$obj_arr[$classname]; 
        }else{
            include_once(ROOT."/".$classname.".class.php");
            $obj = new $classname();
            call_user_func_array (array($obj, "__construct"), $param_arr);
            self::$obj_arr[$classname] = $obj;
            return self::$obj_arr[$classname]; 
        }
        return false;
    }
    
    public static function getObj($classname = ''){
        if($classname == ''){
            return self::$obj_arr;
        }else{
            return self::$obj_arr[$classname];
        }
    }
}

